package com.hui.server.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hui.server.config.redis.RedisCacheConfig;
import com.hui.server.entity.Admin;
import org.apache.ibatis.annotations.*;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;


/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author hui
 * @since 2022-03-31
 */

//@CacheNamespace(implementation = RedisCacheConfig.class)  //启动类中开启了 mapperScan
public interface AdminMapper extends BaseMapper<Admin> {
    /**
     * 动态SQL<p/>
     * 查询除了已经登录以外的其他用户信息，包括用户的角色信息，且按照 keywords 的name字符串进行模糊查询
     * @param id
     * @param keywords
     * @return
     */
    @Select("<script>" +
            "select \n" +
            "`id`, `name`, `phone`, `telephone`, `address`, `enabled`, `username`, `userFace`, `remark`\n" +
            "from \n" +
            "t_admin\n" +
            "where\n" +
            "id != #{id}\n" +
            "<if test=\"null != keywords and '' != keywords\">\n" +
            "and `name` like concat('%',#{keywords},'%')\n" +
            "</if>"+
            "ORDER BY id" +
            "</script>")
    @Results(
            value = {
                    @Result(id = true, property = "id", column = "id"),
                    @Result(property = "roles", many = @Many(select = "com.hui.server.mapper.RoleMapper.getRolesByAdminId"), column = "id")
            }
    )
    List<Admin> getAllAdminsByFuzzyQuery(@Param("id") Integer id, @Param("keywords") String keywords);




}
